package com.gz.moreaseManager.modules.service.impl;

import com.gz.moreaseManager.core.base.Constants;
import com.gz.moreaseManager.modules.entity.Brand;
import com.gz.moreaseManager.modules.mapper.BrandMapper;
import com.gz.moreaseManager.modules.service.IBrandService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.gz.moreaseManager.modules.service.IMenuWebService;
import com.gz.moreaseManager.utils.UtilTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wike
 * @since 2019-02-25
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {

    @Resource
    private BrandMapper brandMapper;

    /**
     * 获取品牌简介信息
     * @return
     */
    public Brand findBrandBrief(){
        List<Brand> list = findBrandByAuthCode(Constants.BRAND_TYPE_INFO);
        if(UtilTool.isNotBlank( list ) &&  list.size() ==1 ){
            return list.get(0);
        }
        return null;
    }
    /**
     * 获取品牌文化
     * @return
     */
    public Brand findBrandCulture(){
        List<Brand> list = findBrandByAuthCode(Constants.BRAND_TYPE_CULTURE);
        if(UtilTool.isNotBlank( list ) &&  list.size() ==1 ){
            return list.get(0);
        }
        return null;
    }

    /**
     * 获取品牌历史
     * @return
     */
    public List<Brand> findBrandHistory(Integer year){
        List<Brand> list = findBrandByAuthCode(Constants.BRAND_TYPE_HISTORY);
        if( UtilTool.isNotBlank( year ))
            list = findBrandByAuthCodeAndYear(Constants.BRAND_TYPE_HISTORY,year);
        if(UtilTool.isNotBlank( list ) &&  list.size() >0 ){
            return list;
        }
        return null;
    }

    /**
     * 获取品牌历史对应的年份
     * @return
     */
    public Map findBrandHistoryYearList(){
        Map list = brandMapper.findBrandYearList(Constants.BRAND_TYPE_HISTORY);
        if(UtilTool.isNotBlank( list ) ){
            return list;
        }
        return null;
    }

    /**
     * 获取品牌荣誉
     * @return
     */
    public List<Brand> findBrandReput(Integer year){
        List<Brand> list = findBrandByAuthCode(Constants.BRAND_TYPE_REPUT);
        if( UtilTool.isNotBlank( year ))
           list = findBrandByAuthCodeAndYear(Constants.BRAND_TYPE_REPUT,year);
        if(UtilTool.isNotBlank( list ) &&  list.size() > 0 ){
            return list;
        }
        return null;
    }

    /**
     * 获取品牌荣誉对应的年份
     * @return
     */
    public Map findBrandReputYearList(){
        Map map = brandMapper.findBrandYearList(Constants.BRAND_TYPE_REPUT);
        if(UtilTool.isNotBlank( map )  ){
            return map;
        }
        return null;
    }

    /**
     * 获取工艺
     * @return
     */
    public Brand findBrandTechnology(){
        List<Brand> list = findBrandByAuthCode(Constants.BRAND_TYPE_TECHNOLOGY);
        if(UtilTool.isNotBlank( list ) &&  list.size() ==1 ){
            return list.get(0);
        }
        return null;
    }

    /**
     * 根据权限码获取信息
     * @param authCode
     * @return
     */
    private List<Brand> findBrandByAuthCode(String authCode ){

        if( UtilTool.isNotBlank( authCode )){
            List<Brand> brandList= brandMapper.findBrandByAuthCode( authCode );
            if( UtilTool.isNotBlank( brandList ) && brandList.size() > 0)
                return brandList;
        }
        return null;
    }

    /**
     * 根据权限码获取信息
     * @param authCode
     * @return
     */
    private List<Brand> findBrandByAuthCodeAndYear(String authCode ,Integer year ){

        if( UtilTool.isNotBlank( authCode ) && UtilTool.isNotBlank( year )){
            List<Brand> brandList= brandMapper.findBrandByAuthCodeAndYear( authCode,year );
            if( UtilTool.isNotBlank( brandList ) && brandList.size() > 0)
                return brandList;
        }
        return null;
    }

}
